From b23ffc34407dd9e5cf7aec67c8618d329b36bca0 Mon Sep 17 00:00:00 2001
From: Fuwn <contact@fuwn.me>
Date: Fri, 19 Apr 2024 16:52:28 -0700
Subject: refactor(image): move cdn to image

---
 src/routes/user/[user]/badges/+page.svelte | 29 ++---------------------------
 1 file changed, 2 insertions(+), 27 deletions(-)

(limited to 'src/routes/user/[user]/badges/+page.svelte')

diff --git a/src/routes/user/[user]/badges/+page.svelte b/src/routes/user/[user]/badges/+page.svelte
index 7db57cd1..8adacce0 100644
--- a/src/routes/user/[user]/badges/+page.svelte
+++ b/src/routes/user/[user]/badges/+page.svelte
@@ -9,7 +9,7 @@
 	import root from '$lib/Utility/root.js';
 	import tooltip from '$lib/Tooltip/tooltip.js';
 	import proxy from '$lib/Utility/proxy.js';
-	import cdn from '$lib/Utility/cdn.js';
+	import { cdn } from '$lib/Utility/image';
 	import locale from '$stores/locale.js';
 	import Skeleton from '$lib/Loading/Skeleton.svelte';
 	import Message from '$lib/Loading/Message.svelte';
@@ -26,6 +26,7 @@
 	// import { io } from 'socket.io-client';
 	import Tooltip from '$lib/Tooltip/LinkedTooltip.svelte';
 	import BadgePreview from '$lib/BadgeWall/BadgePreview.svelte';
+	import { thumbnail } from '$lib/Utility/image.js';
 
 	export let data;
 
@@ -321,32 +322,6 @@
 			}, {});
 	};
 
-	const thumbnail = (url: string | undefined) => {
-		const width = 144;
-		const height = 200;
-
-		if (url && url.includes('catbox.moe') && !url.includes('gif'))
-			return url.replace('catbox.moe/', 'catbox.moe/thumbs/t_');
-
-		if (url && url.includes('imgur') && !url.includes('gif'))
-			return (!url.includes('i.imgur.com') ? url.replace('imgur.com', 'i.imgur.com') : url).replace(
-				/(\.\w+)$/,
-				`_d.webp?maxwidth=${width}&shape=thumb&fidelity=high`
-			);
-
-		if (url && url.includes('discordapp')) {
-			const match = url.match(/attachments\/(\d+)\/(\d+)\/(.+)/);
-
-			if (match) {
-				const [_, server, id, file] = match;
-
-				return `https://media.discordapp.net/attachments/${server}/${id}/${file}?width=${width}&height=${height}`;
-			}
-		}
-
-		return url;
-	};
-
 	const parsePost = async () => {
 		if (importImages && importImages.length > 0) importImages = undefined;
 
-- 
cgit v1.2.3

